package xyz.yuzegod.megawalls.game.stage;

import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.event.Event;
import org.bukkit.plugin.Plugin;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import xyz.yuzegod.megawalls.MegaWalls;
import xyz.yuzegod.megawalls.event.WallFallEvent;
import xyz.yuzegod.megawalls.game.Game;
import xyz.yuzegod.megawalls.game.GamePlayer;
import xyz.yuzegod.megawalls.game.GameType;
import xyz.yuzegod.megawalls.game.GameWall;
import xyz.yuzegod.megawalls.timer.ScoreBoardTimer;
import xyz.yuzegod.megawalls.timer.WitherSpecialAttackTimer;

public class WallFallStage extends GameStage
{
    public WallFallStage() {
        super("距离高墙倒塌还有", ((MegaWalls.getInstance().getGame().getGameType() == GameType.NORMAL) ? 6 : 10) * 60, 0, 1);
    }
    
    @Override
    public void excute(final Game game) {
        for (final GameWall gameWall : game.getWalls()) {
            gameWall.falldown();
        }
        Bukkit.getPluginManager().callEvent((Event)new WallFallEvent(game));
        game.setWallsFall(true);
        game.setWitherAngry(true);
        game.broadcastMessage("§e§l墙倒了！§c§l开战！");
        game.broadcastTitle("§c墙倒了！", "§e准备战斗！", 10, 40, 10);
        game.broadcastSound(Sound.ENDERDRAGON_GROWL, 1.0f, 1.0f);
        for (final GamePlayer gamePlayer:MegaWalls.getIngame()){
            gamePlayer.getPlayer().removePotionEffect(PotionEffectType.SATURATION);
            gamePlayer.getPlayer().removePotionEffect(PotionEffectType.REGENERATION);
        }
        ScoreBoardTimer.scoreboards.clear();
        Bukkit.getScheduler().runTaskTimer((Plugin)MegaWalls.getInstance(), (BukkitRunnable)new WitherSpecialAttackTimer(game), 0L, 100L);
        Bukkit.getScheduler().runTaskLater((Plugin)MegaWalls.getInstance(), (Runnable)new Runnable() {
            @Override
            public void run() {
                game.registerScoreboardTeams();
            }
        }, 30L);
    }
    
    @Override
    public void excuteLeftSeconds(final Game game, final int left) {
    }
}
